package com.zerui.manager.access.auth.task.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zerui.manager.access.auth.task.domain.AuthTask;
import lombok.Getter;
import lombok.Setter;

import java.time.LocalDateTime;

@Getter
@Setter
@TableName("tb_access_auth_task")
public class AccessAuthTaskDO {
    /**
     * 主键
     */
    @TableId(type = IdType.AUTO)
    private Long id;
    /**
     * 权限组
     */
    private Long accessAuthId;
    /**
     * 操作（0 - 添加；1 - 删除）
     */
    private Integer operate;
    /**
     * 任务下发原因
     */
    private String reason;
    /**
     * 任务下发状态（0 - 未执行；1 - 执行中；2 - 执行失败； 3 - 执行成功）
     */
    private Integer syncStatus;
    /**
     * 创建时间
     */
    private LocalDateTime createTime;
    /**
     * 更新时间
     */
    private LocalDateTime updateTime;

    public static AccessAuthTaskDO of(AuthTask task) {
        AccessAuthTaskDO entity = new AccessAuthTaskDO();
        entity.accessAuthId = task.getAccessAuthId();
        entity.operate = task.getOperate();
        entity.reason = task.getReason();
        entity.syncStatus = 0;
        entity.createTime = LocalDateTime.now();
        entity.updateTime = LocalDateTime.now();
        return entity;
    }

    public AuthTask toAuthTask() {
        AuthTask entity = new AuthTask();
        entity.setAccessAuthId(this.getAccessAuthId());
        entity.setOperate(this.getOperate());
        entity.setReason(this.getReason());
        entity.setSyncStatus(this.getSyncStatus());
        return entity;
    }
}
